<?php


/**
 * Base class that represents a query for the 'customer' table.
 *
 * 
 *
 * @method     CustomerQuery orderByPersonid($order = Criteria::ASC) Order by the personid column
 * @method     CustomerQuery orderByCcnr($order = Criteria::ASC) Order by the ccnr column
 * @method     CustomerQuery orderByIban($order = Criteria::ASC) Order by the iban column
 * @method     CustomerQuery orderByBic($order = Criteria::ASC) Order by the bic column
 * @method     CustomerQuery orderByPremium($order = Criteria::ASC) Order by the premium column
 *
 * @method     CustomerQuery groupByPersonid() Group by the personid column
 * @method     CustomerQuery groupByCcnr() Group by the ccnr column
 * @method     CustomerQuery groupByIban() Group by the iban column
 * @method     CustomerQuery groupByBic() Group by the bic column
 * @method     CustomerQuery groupByPremium() Group by the premium column
 *
 * @method     CustomerQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method     CustomerQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method     CustomerQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method     CustomerQuery leftJoinPerson($relationAlias = null) Adds a LEFT JOIN clause to the query using the Person relation
 * @method     CustomerQuery rightJoinPerson($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Person relation
 * @method     CustomerQuery innerJoinPerson($relationAlias = null) Adds a INNER JOIN clause to the query using the Person relation
 *
 * @method     CustomerQuery leftJoinReservation($relationAlias = null) Adds a LEFT JOIN clause to the query using the Reservation relation
 * @method     CustomerQuery rightJoinReservation($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Reservation relation
 * @method     CustomerQuery innerJoinReservation($relationAlias = null) Adds a INNER JOIN clause to the query using the Reservation relation
 *
 * @method     CustomerQuery leftJoinWebuser($relationAlias = null) Adds a LEFT JOIN clause to the query using the Webuser relation
 * @method     CustomerQuery rightJoinWebuser($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Webuser relation
 * @method     CustomerQuery innerJoinWebuser($relationAlias = null) Adds a INNER JOIN clause to the query using the Webuser relation
 *
 * @method     Customer findOne(PropelPDO $con = null) Return the first Customer matching the query
 * @method     Customer findOneOrCreate(PropelPDO $con = null) Return the first Customer matching the query, or a new Customer object populated from the query conditions when no match is found
 *
 * @method     Customer findOneByPersonid(int $personid) Return the first Customer filtered by the personid column
 * @method     Customer findOneByCcnr(string $ccnr) Return the first Customer filtered by the ccnr column
 * @method     Customer findOneByIban(string $iban) Return the first Customer filtered by the iban column
 * @method     Customer findOneByBic(string $bic) Return the first Customer filtered by the bic column
 * @method     Customer findOneByPremium(boolean $premium) Return the first Customer filtered by the premium column
 *
 * @method     array findByPersonid(int $personid) Return Customer objects filtered by the personid column
 * @method     array findByCcnr(string $ccnr) Return Customer objects filtered by the ccnr column
 * @method     array findByIban(string $iban) Return Customer objects filtered by the iban column
 * @method     array findByBic(string $bic) Return Customer objects filtered by the bic column
 * @method     array findByPremium(boolean $premium) Return Customer objects filtered by the premium column
 *
 * @package    propel.generator.ise-php.om
 */
abstract class BaseCustomerQuery extends ModelCriteria
{
	
	/**
	 * Initializes internal state of BaseCustomerQuery object.
	 *
	 * @param     string $dbName The dabase name
	 * @param     string $modelName The phpName of a model, e.g. 'Book'
	 * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
	 */
	public function __construct($dbName = 'ise-php', $modelName = 'Customer', $modelAlias = null)
	{
		parent::__construct($dbName, $modelName, $modelAlias);
	}

	/**
	 * Returns a new CustomerQuery object.
	 *
	 * @param     string $modelAlias The alias of a model in the query
	 * @param     Criteria $criteria Optional Criteria to build the query from
	 *
	 * @return    CustomerQuery
	 */
	public static function create($modelAlias = null, $criteria = null)
	{
		if ($criteria instanceof CustomerQuery) {
			return $criteria;
		}
		$query = new CustomerQuery();
		if (null !== $modelAlias) {
			$query->setModelAlias($modelAlias);
		}
		if ($criteria instanceof Criteria) {
			$query->mergeWith($criteria);
		}
		return $query;
	}

	/**
	 * Find object by primary key.
	 * Propel uses the instance pool to skip the database if the object exists.
	 * Go fast if the query is untouched.
	 *
	 * <code>
	 * $obj  = $c->findPk(12, $con);
	 * </code>
	 *
	 * @param     mixed $key Primary key to use for the query
	 * @param     PropelPDO $con an optional connection object
	 *
	 * @return    Customer|array|mixed the result, formatted by the current formatter
	 */
	public function findPk($key, $con = null)
	{
		if ($key === null) {
			return null;
		}
		if ((null !== ($obj = CustomerPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
			// the object is alredy in the instance pool
			return $obj;
		}
		if ($con === null) {
			$con = Propel::getConnection(CustomerPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}
		$this->basePreSelect($con);
		if ($this->formatter || $this->modelAlias || $this->with || $this->select
		 || $this->selectColumns || $this->asColumns || $this->selectModifiers
		 || $this->map || $this->having || $this->joins) {
			return $this->findPkComplex($key, $con);
		} else {
			return $this->findPkSimple($key, $con);
		}
	}

	/**
	 * Find object by primary key using raw SQL to go fast.
	 * Bypass doSelect() and the object formatter by using generated code.
	 *
	 * @param     mixed $key Primary key to use for the query
	 * @param     PropelPDO $con A connection object
	 *
	 * @return    Customer A model object, or null if the key is not found
	 */
	protected function findPkSimple($key, $con)
	{
		$sql = 'SELECT `PERSONID`, `CCNR`, `IBAN`, `BIC`, `PREMIUM` FROM `customer` WHERE `PERSONID` = :p0';
		try {
			$stmt = $con->prepare($sql);			
			$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
			$stmt->execute();
		} catch (Exception $e) {
			Propel::log($e->getMessage(), Propel::LOG_ERR);
			throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
		}
		$obj = null;
		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$obj = new Customer();
			$obj->hydrate($row);
			CustomerPeer::addInstanceToPool($obj, (string) $key);
		}
		$stmt->closeCursor();

		return $obj;
	}

	/**
	 * Find object by primary key.
	 *
	 * @param     mixed $key Primary key to use for the query
	 * @param     PropelPDO $con A connection object
	 *
	 * @return    Customer|array|mixed the result, formatted by the current formatter
	 */
	protected function findPkComplex($key, $con)
	{
		// As the query uses a PK condition, no limit(1) is necessary.
		$criteria = $this->isKeepQuery() ? clone $this : $this;
		$stmt = $criteria
			->filterByPrimaryKey($key)
			->doSelect($con);
		return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
	}

	/**
	 * Find objects by primary key
	 * <code>
	 * $objs = $c->findPks(array(12, 56, 832), $con);
	 * </code>
	 * @param     array $keys Primary keys to use for the query
	 * @param     PropelPDO $con an optional connection object
	 *
	 * @return    PropelObjectCollection|array|mixed the list of results, formatted by the current formatter
	 */
	public function findPks($keys, $con = null)
	{
		if ($con === null) {
			$con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
		}
		$this->basePreSelect($con);
		$criteria = $this->isKeepQuery() ? clone $this : $this;
		$stmt = $criteria
			->filterByPrimaryKeys($keys)
			->doSelect($con);
		return $criteria->getFormatter()->init($criteria)->format($stmt);
	}

	/**
	 * Filter the query by primary key
	 *
	 * @param     mixed $key Primary key to use for the query
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByPrimaryKey($key)
	{
		return $this->addUsingAlias(CustomerPeer::PERSONID, $key, Criteria::EQUAL);
	}

	/**
	 * Filter the query by a list of primary keys
	 *
	 * @param     array $keys The list of primary key to use for the query
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByPrimaryKeys($keys)
	{
		return $this->addUsingAlias(CustomerPeer::PERSONID, $keys, Criteria::IN);
	}

	/**
	 * Filter the query on the personid column
	 *
	 * Example usage:
	 * <code>
	 * $query->filterByPersonid(1234); // WHERE personid = 1234
	 * $query->filterByPersonid(array(12, 34)); // WHERE personid IN (12, 34)
	 * $query->filterByPersonid(array('min' => 12)); // WHERE personid > 12
	 * </code>
	 *
	 * @see       filterByPerson()
	 *
	 * @param     mixed $personid The value to use as filter.
	 *              Use scalar values for equality.
	 *              Use array values for in_array() equivalent.
	 *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByPersonid($personid = null, $comparison = null)
	{
		if (is_array($personid) && null === $comparison) {
			$comparison = Criteria::IN;
		}
		return $this->addUsingAlias(CustomerPeer::PERSONID, $personid, $comparison);
	}

	/**
	 * Filter the query on the ccnr column
	 *
	 * Example usage:
	 * <code>
	 * $query->filterByCcnr('fooValue');   // WHERE ccnr = 'fooValue'
	 * $query->filterByCcnr('%fooValue%'); // WHERE ccnr LIKE '%fooValue%'
	 * </code>
	 *
	 * @param     string $ccnr The value to use as filter.
	 *              Accepts wildcards (* and % trigger a LIKE)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByCcnr($ccnr = null, $comparison = null)
	{
		if (null === $comparison) {
			if (is_array($ccnr)) {
				$comparison = Criteria::IN;
			} elseif (preg_match('/[\%\*]/', $ccnr)) {
				$ccnr = str_replace('*', '%', $ccnr);
				$comparison = Criteria::LIKE;
			}
		}
		return $this->addUsingAlias(CustomerPeer::CCNR, $ccnr, $comparison);
	}

	/**
	 * Filter the query on the iban column
	 *
	 * Example usage:
	 * <code>
	 * $query->filterByIban('fooValue');   // WHERE iban = 'fooValue'
	 * $query->filterByIban('%fooValue%'); // WHERE iban LIKE '%fooValue%'
	 * </code>
	 *
	 * @param     string $iban The value to use as filter.
	 *              Accepts wildcards (* and % trigger a LIKE)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByIban($iban = null, $comparison = null)
	{
		if (null === $comparison) {
			if (is_array($iban)) {
				$comparison = Criteria::IN;
			} elseif (preg_match('/[\%\*]/', $iban)) {
				$iban = str_replace('*', '%', $iban);
				$comparison = Criteria::LIKE;
			}
		}
		return $this->addUsingAlias(CustomerPeer::IBAN, $iban, $comparison);
	}

	/**
	 * Filter the query on the bic column
	 *
	 * Example usage:
	 * <code>
	 * $query->filterByBic('fooValue');   // WHERE bic = 'fooValue'
	 * $query->filterByBic('%fooValue%'); // WHERE bic LIKE '%fooValue%'
	 * </code>
	 *
	 * @param     string $bic The value to use as filter.
	 *              Accepts wildcards (* and % trigger a LIKE)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByBic($bic = null, $comparison = null)
	{
		if (null === $comparison) {
			if (is_array($bic)) {
				$comparison = Criteria::IN;
			} elseif (preg_match('/[\%\*]/', $bic)) {
				$bic = str_replace('*', '%', $bic);
				$comparison = Criteria::LIKE;
			}
		}
		return $this->addUsingAlias(CustomerPeer::BIC, $bic, $comparison);
	}

	/**
	 * Filter the query on the premium column
	 *
	 * Example usage:
	 * <code>
	 * $query->filterByPremium(true); // WHERE premium = true
	 * $query->filterByPremium('yes'); // WHERE premium = true
	 * </code>
	 *
	 * @param     boolean|string $premium The value to use as filter.
	 *              Non-boolean arguments are converted using the following rules:
	 *                * 1, '1', 'true',  'on',  and 'yes' are converted to boolean true
	 *                * 0, '0', 'false', 'off', and 'no'  are converted to boolean false
	 *              Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByPremium($premium = null, $comparison = null)
	{
		if (is_string($premium)) {
			$premium = in_array(strtolower($premium), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
		}
		return $this->addUsingAlias(CustomerPeer::PREMIUM, $premium, $comparison);
	}

	/**
	 * Filter the query by a related Person object
	 *
	 * @param     Person|PropelCollection $person The related object(s) to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByPerson($person, $comparison = null)
	{
		if ($person instanceof Person) {
			return $this
				->addUsingAlias(CustomerPeer::PERSONID, $person->getPersonid(), $comparison);
		} elseif ($person instanceof PropelCollection) {
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
			return $this
				->addUsingAlias(CustomerPeer::PERSONID, $person->toKeyValue('PrimaryKey', 'Personid'), $comparison);
		} else {
			throw new PropelException('filterByPerson() only accepts arguments of type Person or PropelCollection');
		}
	}

	/**
	 * Adds a JOIN clause to the query using the Person relation
	 *
	 * @param     string $relationAlias optional alias for the relation
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function joinPerson($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		$tableMap = $this->getTableMap();
		$relationMap = $tableMap->getRelation('Person');

		// create a ModelJoin object for this join
		$join = new ModelJoin();
		$join->setJoinType($joinType);
		$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
		if ($previousJoin = $this->getPreviousJoin()) {
			$join->setPreviousJoin($previousJoin);
		}

		// add the ModelJoin to the current object
		if($relationAlias) {
			$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
			$this->addJoinObject($join, $relationAlias);
		} else {
			$this->addJoinObject($join, 'Person');
		}

		return $this;
	}

	/**
	 * Use the Person relation Person object
	 *
	 * @see       useQuery()
	 *
	 * @param     string $relationAlias optional alias for the relation,
	 *                                   to be used as main alias in the secondary query
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    PersonQuery A secondary query class using the current class as primary query
	 */
	public function usePersonQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		return $this
			->joinPerson($relationAlias, $joinType)
			->useQuery($relationAlias ? $relationAlias : 'Person', 'PersonQuery');
	}

	/**
	 * Filter the query by a related Reservation object
	 *
	 * @param     Reservation $reservation  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByReservation($reservation, $comparison = null)
	{
		if ($reservation instanceof Reservation) {
			return $this
				->addUsingAlias(CustomerPeer::PERSONID, $reservation->getCustomerid(), $comparison);
		} elseif ($reservation instanceof PropelCollection) {
			return $this
				->useReservationQuery()
				->filterByPrimaryKeys($reservation->getPrimaryKeys())
				->endUse();
		} else {
			throw new PropelException('filterByReservation() only accepts arguments of type Reservation or PropelCollection');
		}
	}

	/**
	 * Adds a JOIN clause to the query using the Reservation relation
	 *
	 * @param     string $relationAlias optional alias for the relation
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function joinReservation($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		$tableMap = $this->getTableMap();
		$relationMap = $tableMap->getRelation('Reservation');

		// create a ModelJoin object for this join
		$join = new ModelJoin();
		$join->setJoinType($joinType);
		$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
		if ($previousJoin = $this->getPreviousJoin()) {
			$join->setPreviousJoin($previousJoin);
		}

		// add the ModelJoin to the current object
		if($relationAlias) {
			$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
			$this->addJoinObject($join, $relationAlias);
		} else {
			$this->addJoinObject($join, 'Reservation');
		}

		return $this;
	}

	/**
	 * Use the Reservation relation Reservation object
	 *
	 * @see       useQuery()
	 *
	 * @param     string $relationAlias optional alias for the relation,
	 *                                   to be used as main alias in the secondary query
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    ReservationQuery A secondary query class using the current class as primary query
	 */
	public function useReservationQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		return $this
			->joinReservation($relationAlias, $joinType)
			->useQuery($relationAlias ? $relationAlias : 'Reservation', 'ReservationQuery');
	}

	/**
	 * Filter the query by a related Webuser object
	 *
	 * @param     Webuser $webuser  the related object to use as filter
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function filterByWebuser($webuser, $comparison = null)
	{
		if ($webuser instanceof Webuser) {
			return $this
				->addUsingAlias(CustomerPeer::PERSONID, $webuser->getPersonid(), $comparison);
		} elseif ($webuser instanceof PropelCollection) {
			return $this
				->useWebuserQuery()
				->filterByPrimaryKeys($webuser->getPrimaryKeys())
				->endUse();
		} else {
			throw new PropelException('filterByWebuser() only accepts arguments of type Webuser or PropelCollection');
		}
	}

	/**
	 * Adds a JOIN clause to the query using the Webuser relation
	 *
	 * @param     string $relationAlias optional alias for the relation
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function joinWebuser($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		$tableMap = $this->getTableMap();
		$relationMap = $tableMap->getRelation('Webuser');

		// create a ModelJoin object for this join
		$join = new ModelJoin();
		$join->setJoinType($joinType);
		$join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
		if ($previousJoin = $this->getPreviousJoin()) {
			$join->setPreviousJoin($previousJoin);
		}

		// add the ModelJoin to the current object
		if($relationAlias) {
			$this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
			$this->addJoinObject($join, $relationAlias);
		} else {
			$this->addJoinObject($join, 'Webuser');
		}

		return $this;
	}

	/**
	 * Use the Webuser relation Webuser object
	 *
	 * @see       useQuery()
	 *
	 * @param     string $relationAlias optional alias for the relation,
	 *                                   to be used as main alias in the secondary query
	 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
	 *
	 * @return    WebuserQuery A secondary query class using the current class as primary query
	 */
	public function useWebuserQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
	{
		return $this
			->joinWebuser($relationAlias, $joinType)
			->useQuery($relationAlias ? $relationAlias : 'Webuser', 'WebuserQuery');
	}

	/**
	 * Exclude object from result
	 *
	 * @param     Customer $customer Object to remove from the list of results
	 *
	 * @return    CustomerQuery The current query, for fluid interface
	 */
	public function prune($customer = null)
	{
		if ($customer) {
			$this->addUsingAlias(CustomerPeer::PERSONID, $customer->getPersonid(), Criteria::NOT_EQUAL);
		}

		return $this;
	}

} // BaseCustomerQuery